﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BlogEngine.Core
{
    /// <summary>
    /// Custom <see cref="T:System.Collections.Generic.List"/> collection for <see cref="T:BlogEngine.Core.CultureCollectionItem"/> item type.
    /// </summary>
    public class CultureCollection : List<CultureCollectionItem>
    {
        /// <summary>
        /// Gets the culture item based on culture name.
        /// </summary>
        /// <param name="cultureName">Culture name (en, fr, cs, etc.)</param>
        /// <returns>Returns the item from the collection.</returns>
        public CultureCollectionItem this[string cultureName]
        {
            get
            {
                foreach (CultureCollectionItem item in this)
                {
                    if (item.CultureName == cultureName)
                        return item;
                }
                return null;
            }
        }

        /// <summary>
        /// Gets the culture item based on culture ID of integer data type.
        /// </summary>
        /// <param name="cultureId">Culture ID used in data storage (XML, SQL)</param>
        /// <returns>Returns the item from the collection.</returns>
        public new CultureCollectionItem this[int cultureId]
        {
            get { return this[(byte)cultureId]; }
        }

        /// <summary>
        /// Gets the culture item based on culture ID of byte data type (equals SQL tinyint data type).
        /// </summary>
        /// <param name="cultureId">Culture ID used in data storage (XML, SQL)</param>
        /// <returns>Returns the item from the collection</returns>
        public CultureCollectionItem this[byte cultureId]
        {
            get
            {
                foreach (CultureCollectionItem item in this)
                {
                    if (item.CultureID == cultureId)
                        return item;
                }
                return null;
            }
        }
    }
}
